from wxpyview.ui.component.widgets.sizer.box.BoxSizer import *
from wxpyview.ui.component.widgets.sizer.box.BoxItem import *

class VBox(BoxSizer):
    def create(self, meta_widget):
        sizer = wx.BoxSizer(wx.VERTICAL)
        
        parent = self._getParentParam(meta_widget)
        
        parent_classname = parent.__class__.__name__

        if parent_classname not in ['BoxSizer', 'FlexGridSizer']:
            parent.SetSizer(sizer)
                    
        return sizer
    
    @classmethod
    def finalize(cls, meta_widget):
        current_widget = meta_widget.getWidget()
        
        child_meta_widgets = meta_widget.getChildMetaWidgets()
        
        for m_widget in child_meta_widgets:
            child_widget = m_widget.getWidget()
            
            if child_widget.__class__.__name__ != 'BoxItem':
                raise IOException
            
            boxItem_sizer_params = child_widget.getSizerParams()
            
            widgets = BoxItem.getWidget(m_widget)
            if widgets == []: continue
            
            for widget in widgets:
                current_widget.Add(widget, **boxItem_sizer_params)